TARGET = dskfmt_tool
OUT_DIR = ./out
INC_DIR = -I./include
IMG_DIR = ./image

CC = gcc
LIBS = -lc
LIB_DIR = -L/usr/lib/x86_64-linux-gnu/

SRC_FILES = ./core/*.c \
		    ./dsk/dfl/*.c \
		    ./fs/fat32_img/*.c \
		    ./main/*.c

SRCS = $(wildcard $(SRC_FILES))
OBJS = $(SRCS:.c=.o)

# gcc hello.c -Wl,--verbose 可以获取默认的链接脚本
all:
	$(CC) $(INC_DIR) $(SRCS) -o $(OUT_DIR)/$(TARGET) -Tdskfmt.lds

MNT_DIR = $(IMG_DIR)/mnt
IMG_NAME = fat32_image
SECTOR = 512
COUNT = 65536

img:
	dd if=/dev/zero of=$(IMG_DIR)/$(IMG_NAME) bs=$(SECTOR) count=$(COUNT)
	mkfs.vfat -F 32 $(IMG_DIR)/$(IMG_NAME)
	cp $(IMG_DIR)/$(IMG_NAME) $(IMG_DIR)/$(IMG_NAME)-cp
	sudo mount -o loop $(IMG_DIR)/$(IMG_NAME) $(MNT_DIR)

u_img:
	sudo umount $(MNT_DIR)
	sudo rm $(IMG_DIR)/* -rf
	mkdir $(MNT_DIR)

F_NAME =
file:
	dd if=/dev/zero of=$(IMG_DIR)/$(F_NAME) bs=$(SECTOR) count=$(COUNT)
	sudo mv $(IMG_DIR)/$(F_NAME) $(MNT_DIR)

diff:
	xxd $(IMG_DIR)/$(IMG_NAME) > $(IMG_DIR)/$(IMG_NAME).hex
	xxd $(IMG_DIR)/$(IMG_NAME)-cp > $(IMG_DIR)/$(IMG_NAME)-cp.hex
	diff $(IMG_DIR)/$(IMG_NAME).hex $(IMG_DIR)/$(IMG_NAME)-cp.hex -y

clean:
	rm $(OUT_DIR)/*